<template>
  <div class="announcementList_container pl-1 pr-1">
    <div
      class="announcementList_container_list br-16"
      v-for="(item, index) in announcementList"
      :key="index"
			@click="goAnnouncementListDetail(item.id)"
    >
      <div class="announcementList_container_list_content">
        <div class="announcementList_container_list_title fs-lh-2 font-left pl-1 pr-1">
          {{ item.title }}
        </div>
        <div class="announcementList_container_list_date font-left pl-1 pr-1">
          {{ item.date }}
        </div>
      </div>
    </div>
    <van-empty v-if="!announcementList.length" :description="$t('暂无数据')"></van-empty>
  </div>
</template>

<script>
import { getAnnounceList } from "@/request/homePage"
export default {
  name: "AnnouncementList",
  data() {
    return {
      announcementList: [
      ],
    };
  },
  mounted() {
    // 请求公告列表数据
    this.getAnnounceList();
  },
  methods: {
    async getAnnounceList() {
      getAnnounceList({}).then((res) => {
        if(res.code == 1){
          this.announcementList = [];
          res.data.data.forEach(item => {
            this.announcementList.push({
              id: item.id,
              title: item.data || item.zh_cn,
              date: item.createtime
            })
          })
        }
      })
    },
		goAnnouncementListDetail(id){
			// 跳转公告列表详情页
			if (this.$route.name !== 'AnnouncementListDetail') {
				this.$router.push({ 
					name: 'AnnouncementListDetail',
					params: { 
						id:id
					}
				})
			}
		}
	},
};
</script>

<style>
</style>